// 提交链接：https://leetcode.cn/problems/design-a-food-rating-system/
// lc2353. 设计食物评分系统
// 完成日期：2024/9/24
// c++ 哈希表 堆

class FoodRatings {
public:
    typedef pair<int,string> p;
    map<string,p> mp1;       //通过食物名查找对应的烹饪方式及评分
    map<string,set<p>>mp2;   //相同烹饪方式的食物集合，set<Key>集合是有序的从小到大排列
    FoodRatings(vector<string>& foods, vector<string>& cuisines, vector<int>& ratings) 
    {
        for(int i=0;i<foods.size();i++)
        {
           mp1[foods[i]]=p(ratings[i],cuisines[i]);
           mp2[cuisines[i]].insert(p(-ratings[i],foods[i]));
        }
         
    }
    
    void changeRating(string food, int newRating) 
    {
        p& tmp=mp1[food];
        mp2[tmp.second].erase(p(-tmp.first,food));
        tmp.first=newRating;
        mp2[tmp.second].insert(p(-tmp.first,food));
    }
    
    string highestRated(string cuisine) {
        return mp2[cuisine].begin()->second;

    }
};

